Skip to main content

Create Audit subscription

This endpoint will create a new Audit Record subscription record in the database. The new record will include the streaming and/or associated configurations. Provide info including where the service should forward the Audit Records, the maximum number of records in each payload, and the frequency for sending them.

URL : http://34.122.70.8/api/v1/audit/subscribe

Method : POST

Auth required : YES

HeadersTypeDescription
api-keystringUnique api key provided to each customer

Permissions required : None

Request Body:

FieldTypeDescription
endpoint_urlstringClient webhook URL where data is being sent
start_timeDateDate and time from which Audit Records are to be fetched
fetch_limitNumberMax number of Audit Records being sent to client in each message
read_intervalNumberInterval, in seconds, between each message to be sent to client

Request Body example

{
"endpoint_url": "http://localhost:3000/hook",
"start_time": "2022-12-25 12:33:30+05:30",
"fetch_limit": 100,
"read_interval": 60
}

Response Body:

FieldTypeDescription
statusBooleanStatus of the request
msgstringResponse message from server
dataData Object

Data Object:

FieldTypeDescription
idstringId of the audit subscription table record
start_timeDateDate and time from when Audit Records should be fetched
last_read_atData ObjectTime of the last Audit Record sent via the subscription
endpoint_urlstringClient webhook url where data is being sent
fetch_limitstringMax number of Audit records being sent to client in each message
read_intervalNumberInterval, in seconds, between messages sent to client
statusstringStatus of the subscription. For new subscription, the status will be 'active'.
createdAtDateDate and time subscription was created
updatedAtData ObjectDate and time subscription was last updated

Response Body example

Success Response

Condition : If everything is OK and the subscription does not already exist.

Code : 201 CREATED

Content example

{
"status": true,
"msg": "Audit record subscribed successfully",
"data": [
{
"id": 1,
"start_time": "2022-12-25T07:03:30.000Z",
"last_read_at": null,
"endpoint_url": "http://localhost:3000/hook",
"fetch_limit": 100,
"read_interval": 60,
"status": "active",
"createdAt": "2023-07-12T17:51:58.439Z",
"updatedAt": "2023-07-12T17:51:58.439Z"
}
]
}

Error Responses

Condition : If the subscription already exist.

Code : 400 Bad Request

Content :

{
"status": false,
"error_code": "ALREADY_EXISTS",
"error_msg": "Subscription already exists. Please unsubscribe first to create a new one"
}

Or

Condition : If endpoint_url field is missing.

Code : 400 BAD REQUEST

Content example

{
"error_code": "BAD_DATA",
"error_msg": "Subscription endpoint url not found or invalid"
}

Or

Condition : If some error was encountered while creating the subscription.

Code : 400 BAD REQUEST

Content example

{
"error_code": "AUDIT_SUBSCRIBE_FAILED",
"error_msg": "Failed to subscribe audit"
}

Or

Condition : If api-key not passed in request header or is wrong.

Code : 401 Unauthorized

Content example

{
"status": false,
"error_code": "AUDIT_UNAUTHORIZED",
"error_msg": "Missing/MisMatch API KEY"
}
const fetch = require('node-fetch');

let url = 'http://34.122.70.8/api/v1/audit/subscribe';

let options = {
method: 'POST',
headers: {
'api-key': '<API_KEY>',
'Content-Type': 'application/json'
},
body: '{"endpoint_url":"http://localhost:3000/hook","start_time":"2022-12-25 12:33:30+05:30","fetch_limit":100,"read_interval":60}'
};

fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));